
package com.project.projectA.core.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * 定义标准的rest方法以对应实体对象的操作,以达到统一rest的方法名称, 还可以避免子类需要重复编写@RequestMapping
 * annotation.
 * 
 * 子类要实现某功能只需覆盖下面的方法即可. 注意: 覆盖时请使用@Override,以确保不会发生错误
 * 
 * <pre>
 * /userinfo                => index()
 * /userinfo/new            => _new()
 * /userinfo/{id}           => show()
 * /userinfo/{id}/edit      => edit()
 * /userinfo        POST    => create()
 * /userinfo/{id}   PUT     => update()
 * /userinfo/{id}   DELETE  => delete()
 * /userinfo        DELETE  => batchDelete()
 * </pre>
 *
 * @param <T> 实体对象
 * @param <PK> 实体主键
 * @author wuwei
 */
public class BaseRestController<T, PK> extends BaseController { 

	/**
	 * Index.
	 *
	 * @param request the request
	 * @param response the response
	 * @param model the model
	 * @return the model and view
	 */
	@RequestMapping
	public ModelAndView index(HttpServletRequest request,
			HttpServletResponse response, T model) {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 进入新增.
	 *
	 * @param request the request
	 * @param response the response
	 * @param model the model
	 * @return the model and view
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/new")
	public ModelAndView _new(HttpServletRequest request,
			HttpServletResponse response, T model) throws Exception {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 显示.
	 *
	 * @param id the id
	 * @param request the request
	 * @param response the response
	 * @return the model and view
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/{id}")
	public ModelAndView show(@PathVariable PK id, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 编辑.
	 *
	 * @param id the id
	 * @param request the request
	 * @param response the response
	 * @return the model and view
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/{id}/edit")
	public ModelAndView edit(@PathVariable PK id, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 保存新增.
	 *
	 * @param request the request
	 * @param response the response
	 * @param model the model
	 * @return the model and view
	 * @throws Exception the exception
	 */
	@RequestMapping(method = RequestMethod.POST)
	public ModelAndView create(HttpServletRequest request,
			HttpServletResponse response, T model) throws Exception {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 保存更新.
	 *
	 * @param id the id
	 * @param request the request
	 * @param response the response
	 * @return the model and view
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	public ModelAndView update(@PathVariable PK id, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 删除.
	 *
	 * @param id the id
	 * @param request the request
	 * @param response the response
	 * @return the model and view
	 */
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public ModelAndView delete(@PathVariable PK id, HttpServletRequest request,
			HttpServletResponse response) {
		throw new UnsupportedOperationException("not yet implement");
	}

	/**
	 * 批量删除.
	 *
	 * @param items the items
	 * @param request the request
	 * @param response the response
	 * @return the model and view
	 */
	@RequestMapping(method = RequestMethod.DELETE)
	public ModelAndView batchDelete(@RequestParam("items") PK[] items,
			HttpServletRequest request, HttpServletResponse response) {
		throw new UnsupportedOperationException("not yet implement");
	}
}
